/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package linkeddata.arida.ufc.br.test;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import linkeddata.arida.ufc.br.manager.impl.BuildsSparqlQuery;
import linkeddata.arida.ufc.br.search.HierarchyOfClasses;
import linkeddata.arida.ufc.br.util.OWLUtils;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;

/**
 *
 * @author jeovane
 */
public class AssemblesQuery extends OWLUtils {

    public void executeQuery() throws OWLOntologyCreationException {
        File file = new File("/home/jeovane/Dropbox/NetBeansProjects/JBOS/JBOS/web/prefixes.xml");
        ontologyLoaded();
        BuildsSparqlQuery bsq = new BuildsSparqlQuery(getOntology(), getPm(), getReasoner(), file);

        ArrayList<String> arrayUnion = new ArrayList<String>();
        arrayUnion.add("Drug");
        //arrayUnion.add("GenericDrug");
        //arrayUnion.add("SideEffect");
        //arrayUnion.add("Autor");
        //arrayUnion.add("Livro");

        // FILTER
        Set<String> setFilter = new LinkedHashSet<String>();
        //setFilter.add("?Disease_name, " + "\"protein\", " + "\"i\"");
        //setFilter.add("?Drug_name, " + "\"abc\", " + "\"i\"");

        // OPCIONAL
        Set<String> setOpt = new LinkedHashSet<String>();
        setOpt.add("GenericDrug");
        //setOpt.add("SideEffect");

        //setOpt.add("Mae");

        // DATA PROPERTY
        Set<String> s1 = new LinkedHashSet<String>();
        Set<String> s2 = new LinkedHashSet<String>();
        Set<String> s3 = new LinkedHashSet<String>();
        //Set<String> s4 = new LinkedHashSet<String>();
        
        s1.add("name");
        s2.add("metabolism");
        s2.add("indication");
        s3.add("sideEffectName");
        //s4.add("genericName");

//        setDatatype.add("nomeAutor");
//        setDatatype.add("nomeLivro");
//        setDatatype.add("nomeMae");

        Map<String, Set<String>> mapTeste = new HashMap<String, Set<String>>();
        mapTeste.put("Disease", s1);
        mapTeste.put("SideEffect", s3);
        mapTeste.put("Drug", s2);
        //mapTeste.put("GenericDrug", s4);


//        mapTeste.put("Autor", setDatatype);
//        mapTeste.put("Mae", setDatatype);
//        mapTeste.put("Livro", setDatatype);

        String activeUnion = "";
        
        String jsonTextQuery = "{\"Disease\":[\"name\",\"class\"],\"GenericDrug\":[\"affectedOrganism\",\"genericName\"],\"Drug\":[\"name\",\"pregnancyCategory\",\"indication\"]}";
        String jsonTextOptional = "{\"GenericDrug\":[\"affectedOrganism\"],\"Drug\":[\"pregnancyCategory\",\"indication\"],\"Disease\":[\"class\"]}";
        //String jsonTextOptional = null;
        //String jsonText4 = "{\"Disease\":[\"name\",\"class\"],\"Drug\":[\"pregnancyCategory\",\"indication\"]}";
        //String jsonText4 = "{\"Disease\":[\"name\"]}";
//        if (!activeUnion.isEmpty()) {
//            System.out.println(bsq.buildsSelect(jsonTextQuery, activeUnion));
//
//            for (String s : bsq.buildsWhereUnion(mapTeste)) {
//                //bsq.buildsSelectUnion(mapTeste);
//                //System.out.println(bsq.buildsSelectUnion(mapTeste));
//                System.out.println(s);
//                //bsq.buildsWhereUnion(mapTeste);
//            }
//        } else {
            bsq.buildsSelect(jsonTextQuery, activeUnion);
            System.out.println(bsq.buildsWhere(jsonTextQuery, jsonTextOptional, setFilter));
//        }
    }
    
    public void clazz(){
        HierarchyOfClasses oc = new HierarchyOfClasses(getOntology(), getReasoner(), getPm());
        ontologyLoaded();
        for (String node : oc.CorrectHierarchyOfClasses()){
            System.out.println(node);
        }
    }
}
